<template>
	<view class="">
		<u-navbar :border='true' :placeholder='true' title="详情">
			<view class="flex-center" slot="left">
				<u-icon @click="$back()" style="margin-right: 40rpx;" name="arrow-left" size="19"></u-icon>
				<u-icon class="u-m-l-20" style="margin-left: 130rpx;" @click="scan" name="scan" size="19"></u-icon>
			</view>
		</u-navbar>
		<u-steps class="u-width-100" :current="current" activeColor='#6BBE69' :dot='true'>
			<u-steps-item title="发单"></u-steps-item>
			<u-steps-item title="已打印"></u-steps-item>
			<u-steps-item title="配送中"></u-steps-item>
			<u-steps-item title="已送达"></u-steps-item>
			<u-steps-item title="完成"></u-steps-item>
		</u-steps>
		<view class="u-p-30">
			<view class="flex-between orderbox u-m-t-50 u-font-28">
				<view class="orderbox flex">
					<u-icon size=20 name='map'></u-icon>
					<view class="u-m-l-10">
						<view class="">
							{{address_info.name}}
						</view>
						<view class="" style="color: #999;">
							地址名称：{{address_info.address}}
						</view>
						<view class="" style="color: #999;">
							地址描述：{{address_info.detail}}
						</view>
						<!-- <view class="" style="color: #999;">
							订单位置：21-444-333
						</view>
						<view class="" style="color: #999;">
							本单客服：收银
						</view> -->
					</view>
				</view>
				<button @click="tolocal(address_info.latitude,address_info.longitude,address_info.address)" size='mini'
					class="u-shrink-no" type="primary">地图</button>
			</view>

			<view class="flex-center u-m-tb-10 u-font-28" v-if="orderinfo.pay_status==10">
				扫码支付
			</view>

			<view class="flex-center u-m-tb-10" v-if="orderinfo.pay_status==10">
				<image :src="orderinfo.pay_qrcode" class="w260 h260" mode=""></image>
			</view>
			<view class="" style="margin-top: 16rpx" @click="callphone(address_info.phone)">
				<u-button icon='phone' type="success" text="拨打客户电话"></u-button>
			</view>
			<view class="" @click="cancel()" style="margin-top: 16rpx; ">
				<u-button type="error" text="取消绑定"></u-button>
			</view>
			<view class="flex-between" style="margin-top: 16rpx; " v-if="orderinfo.pay_status==10">
				<view class="u-font-28 blue" style="width: 45%;" @click="init">刷新收款码，慎点！！！</view>
				<view @click="getcach" class="u-font-28 blue" style="width: 45%;">现金收款</view>
			</view>
			<view class="" @click="finish" style="margin-top: 16rpx; ">
				<u-button type='primary' text="我已送达"></u-button>
			</view>
			<view class="" @click="scan" style="margin-top: 16rpx; ">
				<u-button text="继续绑单"></u-button>
			</view>
			<view class="dashed-line u-m-t-30"></view>
			<view class="flex-between u-m-t-30">
				<text>配送员</text>
				<view class="">
					<text>{{orderinfo.run_name}}</text>
					<!-- <text class="u-m-l-10">15323123213</text> -->
				</view>
			</view>
		</view>
		<u-gap class="" height="10" bgColor="#F2F2F2"></u-gap>
		<view class="" style="padding-bottom: 30rpx;">
			<view class="flex u-p-30" style="color: #999;">
				<u-icon name='bag' size=20></u-icon>
				<text class="u-m-l-20">订单内容</text>
			</view>
			<view class="goodsinfo flex " v-for="i in goods_info">
				<image :src="i.goods_image" class="w160 h160 u-shrink-no" mode=""></image>
				<view class="goodsinfo_right u-m-l-20 ">
					<view class="">
						{{i.goods_name}}
					</view>
					<view class="flex-between u-font-28 u-m-t-16 u-font-bold w300" style="color: red;">
						<view>￥{{i.goods_price}}</view>
						<view>X{{i.total_num}}</view>
					</view>
				</view>
			</view>
			
			<view class="goodsinfo_bottom u-m-tb-20 u-font-24">
				<view class=" ">
					<text>订单金额：</text>
					<text style="color: red;">￥{{orderinfo.order_price}}</text>
				</view>
			</view>
			<view class="goodsinfo_bottom  u-font-28">
				<view class="">
					<text>支付方式：</text>
					<text style="color: red;">{{orderinfo.pay_method}}</text>
				</view>
			</view>
		</view>
		<u-gap class="u-m-tb-20" height="10" bgColor="#F2F2F2"></u-gap>
		<view class="u-p-20 u-font-28">
			<view class="">
				订单编号：{{orderinfo.order_no}}
			</view>
			<view class="u-m-tb-20">
				发单时间：{{orderinfo.create_time }}
			</view>
			<view class="" v-if="orderinfo.printer_time">
				打印时间：{{orderinfo.printer_time}}
			</view>
		</view>
		<view class="u-width-100 h100">

		</view>
		<view class="pagebottom u-width-100">
			<view class="flex-between  u-p-20">
				<u-button type="error" text="退出登录"></u-button>
				<u-button @click="$back()" type="primary" text="查看其他订单"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderinfo: {},
				address_info: {},
				goods_info: [],
				current: 0,
				order_id: 0
			};
		},
		onLoad(option) {
			this.order_id = option.order_id
			this.init()
		},
		methods: {
			tolocal(lat, log, name) {
				uni.openLocation({
					latitude: Number(lat),
					longitude: Number(log),
					name
				})
			},
			callphone(phone) {
				uni.makePhoneCall({
					phoneNumber: phone
				})
			},
			init() {
				this.$api.get('/order/my_order_detail', {
					order_id: this.order_id
				}).then(res => {
					this.orderinfo = res.data
					this.address_info = res.data.address_info
					this.goods_info = res.data.goods_info
					if (res.data.delivery_status == 20) {
						this.current = 2
					}
				})
			},
			scan() {
				var that = this
				uni.scanCode({
					success: function(res) {
						that.$api.post('/order/scan_qr', {
							qr_code: res.result
						}).then(res => {
							uni.showModal({
								content: '此订单已绑定',
								success(res) {
									if (res.confirm) {
										uni.reLaunch({
											url: '/pages/index/index'
										})
									} else if (res.cancel) {
										console.log('用户点击取消');
									}

								}
							})
						})
					}
				});
			},
			finish() {
				var that = this
				uni.showModal({
					content: '确认已送达',
					success(res) {
						if (res.confirm) {
							that.$api.post('/order/order_complete', {
								order_id: that.orderinfo.order_id
							}).then(res => {
								that.$toast(res.msg)
								setTimeout(()=>{
									uni.reLaunch({
										url: '/pages/index/index'
									})
								},3000)
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}

					}
				})
			},
			//现金收款
			getcach() {

				var that = this
				uni.showModal({
					content: '确认已现金收款',
					success(res) {
						if (res.confirm) {
							that.$api.post('/order/order_cash_pay', {
								order_id: that.orderinfo.order_id
							}).then(res => {
								that.init()
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}

					}
				})
			},
			cancel() {
				var that = this
				uni.showModal({
					content: '确认取消绑定吗？',
					success(res) {
						if (res.confirm) {
							that.$api.post('/order/order_cancle_run', {
								order_id: that.orderinfo.order_id
							}).then(res => {
								uni.reLaunch({
									url: '/pages/index/index'
								})
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}

					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.orderbox {
		align-items: flex-start;
	}

	.blue {
		background-color: #6D98F7;
		border-radius: 8rpx;
		text-align: center;
		padding: 20rpx 10rpx;
		color: #fff;
	}

	.goodsinfo {
		background: #FAFAFA;
		padding: 10rpx 20rpx;

		.goodsinfo_right {
			height: 160rpx;
			flex-direction: column;
			display: flex;
			justify-content: space-around;
		}

	}

	.goodsinfo_bottom {
		display: flex;
		justify-content: flex-end;
		padding-right: 30rpx;
		font-weight: bold;
	}

	.pagebottom {
		position: fixed;
		bottom: 0;
	}
</style>